package com.ruoyi.training.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.training.dto.SatisfactionSurveyDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.training.domain.SatisfactionSurvey;
import com.ruoyi.training.service.ISatisfactionSurveyService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 满意度调查结果Controller
 * 
 * @author lqx
 * @date 2025-11-11
 */
@RestController
@RequestMapping("/satisfactionSurvey")
public class SatisfactionSurveyController extends BaseController
{
    @Autowired
    private ISatisfactionSurveyService satisfactionSurveyService;

    /**
     * 查询满意度调查结果列表
     */
    @RequiresPermissions("training:satisfactionSurvey:list")
    @GetMapping("/list")
    public TableDataInfo list(SatisfactionSurvey satisfactionSurvey)
    {
        startPage();
        List<SatisfactionSurvey> list = satisfactionSurveyService.selectSatisfactionSurveyList(satisfactionSurvey);
        return getDataTable(list);
    }

    /**
     * 通过班级id和查询参数查询满意度调查结果列表
     * lqx
     */
    @GetMapping("/listBySatisfactionSurveyDto")
    public TableDataInfo listBySatisfactionSurveyDto(SatisfactionSurveyDto satisfactionSurveyDto)
    {
        startPage();
        List<SatisfactionSurveyDto> list = satisfactionSurveyService.selectSatisfactionSurveyListBySatisfactionSurveyDto(satisfactionSurveyDto);
        return getDataTable(list);
    }

    /**
     * 导出满意度调查结果列表
     */
    @RequiresPermissions("training:satisfactionSurvey:export")
    @Log(title = "满意度调查结果", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SatisfactionSurvey satisfactionSurvey)
    {
        List<SatisfactionSurvey> list = satisfactionSurveyService.selectSatisfactionSurveyList(satisfactionSurvey);
        ExcelUtil<SatisfactionSurvey> util = new ExcelUtil<SatisfactionSurvey>(SatisfactionSurvey.class);
        util.exportExcel(response, list, "满意度调查结果数据");
    }

    /**
     * 获取满意度调查结果详细信息
     */
    @RequiresPermissions("training:satisfactionSurvey:query")
    @GetMapping(value = "/{satisfactionSurveyId}")
    public AjaxResult getInfo(@PathVariable("satisfactionSurveyId") String satisfactionSurveyId)
    {
        return success(satisfactionSurveyService.selectSatisfactionSurveyBySatisfactionSurveyId(satisfactionSurveyId));
    }

    /**
     * 新增满意度调查结果
     */
    @RequiresPermissions("training:satisfactionSurvey:add")
    @Log(title = "满意度调查结果", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SatisfactionSurvey satisfactionSurvey)
    {
        String studentId = SecurityUtils.getLoginUser().getSysUser().getStudentId();
        satisfactionSurvey.setStudentId(studentId);
        return toAjax(satisfactionSurveyService.insertSatisfactionSurvey(satisfactionSurvey));
    }

    /**
     * 通过班级id和学员id查询满意度调查结果列表
     * lqx
     */
    @GetMapping("/listByStudentIdAndClassId/{trainingClassId}")
    public AjaxResult listByStudentIdAndClassId(@PathVariable("trainingClassId") String trainingClassId)
    {
        String studentId = SecurityUtils.getLoginUser().getSysUser().getStudentId();
        SatisfactionSurvey satisfactionSurvey = satisfactionSurveyService.selectSatisfactionSurveyListByByStudentIdAndClassId(trainingClassId,studentId);
        return success(satisfactionSurvey);
    }

    /**
     * 修改满意度调查结果
     */
    @RequiresPermissions("training:satisfactionSurvey:edit")
    @Log(title = "满意度调查结果", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SatisfactionSurvey satisfactionSurvey)
    {
        return toAjax(satisfactionSurveyService.updateSatisfactionSurvey(satisfactionSurvey));
    }

    /**
     * 删除满意度调查结果
     */
    @RequiresPermissions("training:satisfactionSurvey:remove")
    @Log(title = "满意度调查结果", businessType = BusinessType.DELETE)
	@DeleteMapping("/{satisfactionSurveyIds}")
    public AjaxResult remove(@PathVariable String[] satisfactionSurveyIds)
    {
        return toAjax(satisfactionSurveyService.deleteSatisfactionSurveyBySatisfactionSurveyIds(satisfactionSurveyIds));
    }
}
